<template>
	<br>
	{{ formItem.t_name }}
	<switch :checked="_switch" @change="change"></switch>

</template>
<script lang="ts" setup>
	import { ref } from 'vue'
	// import { useWebSocket } from "../hook/index";

	const props = defineProps({
		formItem: {
			type: Object,
			required: true,
		},
		ws:
		{
			type:WebSocket,
			required:true
		}
	})
	let _switch = ref(false)
	let _value = ref("off")
	let switchvalue = ref(props.formItem.set_value || '');
	if(props.formItem.set_value=="on")
	{
		_value.value="on"
		_switch.value=true
	}

	// const ws = useWebSocket();


	const change = () => {
		if (_value.value == "start") {
			_value.value = "stop"
		}
		else {
			_value.value = "start"
		}
		props.ws.send({
			data:JSON.stringify({
				page: 5,
				type: -1,
				value: _value.value,
				config_id: props.formItem.id,
				d_no: 1
			})}
		);
	}
</script>